package com.fimuz.mqmeet.api.building.control;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.fimuz.mqmeet.api.building.service.BuildingService;
import com.fimuz.mqmeet.api.building.service.model.CreateOrUpdateSpModel;
import com.fimuz.mqmeet.api.building.service.model.CreateOrUpdateSrModel;
import com.fimuz.mqmeet.api.building.service.model.DeleteSpModel;
import com.fimuz.mqmeet.api.building.service.model.DeleteSrModel;
import com.fimuz.mqmeet.api.building.service.model.GetSpModel;
import com.fimuz.mqmeet.api.building.service.model.GetSrModel;
import com.fimuz.mqmeet.api.building.service.model.ListSpModel;
import com.fimuz.mqmeet.api.building.service.model.ListSrModel;
import com.fosun.spr.core.base.CoBaseControl;
import com.fosun.spr.core.utils.SessionUtils;

@Controller
public class BuildingControl extends CoBaseControl {
	//@Autowired
	@Resource
	private BuildingService buildingService;

	/**
	 * http://127.0.0.1:8080/mq_meet_server/api/building/list
	 * 
	 * @param request
	 * @param spModel
	 * @return
	 */	
	@RequestMapping(value = "/api/building/list",method = RequestMethod.GET)
	public ListSrModel list(HttpServletRequest request, ListSpModel spModel) {
		SessionUtils.fillSpModel(request, spModel);
		ListSrModel srModel = buildingService.list(spModel);
		return srModel;
	}
	/**
	 * http://127.0.0.1:8080/mq_meet_server/api/building/createOrUpdate
{
	"buildingName":"",
	"id":""
}
	 * @param request
	 * @param spModel
	 * @return
	 */	
	@RequestMapping(value = "/api/building/createOrUpdate",method = RequestMethod.POST)
	public CreateOrUpdateSrModel createOrUpdate(HttpServletRequest request,@RequestBody CreateOrUpdateSpModel spModel) {
		SessionUtils.fillSpModel(request, spModel);
		CreateOrUpdateSrModel srModel = buildingService.createOrUpdate(spModel);
		return srModel;
	}
	/**
	 * http://127.0.0.1:8080/mq_meet_server/api/building/delete
{
	"id":""
}
	 * @param request
	 * @param spModel
	 * @return
	 */	
	@RequestMapping(value = "/api/building/delete",method = RequestMethod.POST)
	public DeleteSrModel delete(HttpServletRequest request,@RequestBody DeleteSpModel spModel) {
		SessionUtils.fillSpModel(request, spModel);
		DeleteSrModel srModel = buildingService.delete(spModel);
		return srModel;
	}
	/**
	 * http://127.0.0.1:8080/mq_meet_server/api/building/get
	 * 
	 * @param request
	 * @param spModel
	 * @return
	 */	
	@RequestMapping(value = "/api/building/get",method = RequestMethod.GET)
	public GetSrModel get(HttpServletRequest request, GetSpModel spModel) {
		SessionUtils.fillSpModel(request, spModel);
		GetSrModel srModel = buildingService.get(spModel);
		return srModel;
	}
	
	
	//生成成json的代码
	public static void main(String[] args) throws Exception{
		debugPrintJsonSpModel(new CreateOrUpdateSpModel());
		debugPrintJsonSpModel(new DeleteSpModel());
	}	
}
